﻿using Cx.NetCoreUtils.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
using Xiao.Application.Services.User;
using Xiao.Util;
using Xiao.Web.Code;
using Xiao.Web.Code.HubService;
using Xiao.Web.Code.VM.Hub;

namespace Xiao.Web.Controllers
{
    /// <summary>
    /// 测试模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DebugController : XiaoController
    {
        private readonly IRedisUtil _redisUtil;
        private readonly IHubContext<ChatHub> _chatHub;
        public DebugController(
            IRedisUtil redisUtil,
            IHubContext<ChatHub> chatHub)
        {
            _redisUtil = redisUtil;
            _chatHub = chatHub;
        }
        /// <summary>
        /// 发送测试数据
        /// </summary>
        [HttpPost]
        public async void Go(Gps gps)
        {
            var receive = _redisUtil.Get(gps.Receive.ToString());
            await _chatHub.Clients.Client(receive).SendAsync("data", JsonConvert.SerializeObject(gps));
        }
        /// <summary>
        /// 获取服务器信息
        /// </summary>
        [HttpGet]
        public string GetServiceName()
        {
            return AppSettings.App("ServiceName");
        }
    }
}
